package cn.example.web.db.bean;

import lombok.experimental.Accessors;
import lombok.Data;
import lombok.AccessLevel;
import lombok.Setter;
import java.util.Date;
import org.artifact.core.db.BaseBean;
import org.artifact.core.lang.IServer;
import java.util.Map;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
@Data
@Accessors(chain = true)
@SuppressWarnings({"rawtypes","unchecked"})
/** 游戏码条目 */
public abstract class GameCodeEntry implements BaseBean<GameCodeEntry> {
	/** 主键 */
	private long id;
	/** 组ID */
	private long groupId;
	/** 码 */
	private String code;
	/** 总次数 */
	private int totalUseCount;
	/** 单人次数 */
	private int singleUseCount;
	/** 使用记录 */
	private java.util.HashMap useLog;
	/** 创建时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date createDate;
	/** 修改时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date modifiedDate;
	
	


	


	@Override
	public GameCodeEntry deepCopy() {
		GameCodeEntry gameCodeEntry = null;
		try {
			gameCodeEntry = (GameCodeEntry) super.clone();
			gameCodeEntry.useLog = (java.util.HashMap)this.useLog.clone();
			gameCodeEntry.createDate = (java.util.Date)this.createDate.clone();
			gameCodeEntry.modifiedDate = (java.util.Date)this.modifiedDate.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		onCopy(gameCodeEntry);
		return gameCodeEntry;
	}

	public <T extends GameCodeEntry> T build(GameCodeEntry t){
	    if(t == null) return null;
	    BeanUtil.copyProperties(t, this);
        onRead();
        return (T)this;
	}

	public GameCodeEntry toSave() {
        if(this.id == 0)
            this.id = (long)IServer.me().getContext().getIdFactory().getId();
		Date now = new Date();
		if (createDate==null) {
			createDate = now;
			modifiedDate = now;
		}else {
			modifiedDate = now;
		}
		onWrite();
		return deepCopy();
	}
	


    /**
     * 写数据
     */
    public Object write(){
        Object[] values = new Object[8];
        values[0] = this.id;
        values[1] = this.groupId;
        values[2] = this.code;
        values[3] = this.totalUseCount;
        values[4] = this.singleUseCount;
        values[5] = this.useLog;
        values[6] = this.createDate;
        values[7] = this.modifiedDate;
        return values;
    }

    /**
     * 读数据
     */
    public GameCodeEntry read(Object object){
        Object[] array = (Object[])object;
        this.id = (long)array[0];
        this.groupId = (long)array[1];
        this.code = (String)array[2];
        this.totalUseCount = (int)array[3];
        this.singleUseCount = (int)array[4];
        this.useLog = (java.util.HashMap)array[5];
        this.createDate = (java.util.Date)array[6];
        this.modifiedDate = (java.util.Date)array[7];
        return this;
    }
    /**
     * 克隆之后
     */
    protected void onCopy(GameCodeEntry gameCodeEntry){

    }

    /**
     * 写数据之前
     */
    protected void onWrite(){
    }

    /**
     * 读数据之后
     */
    protected void onRead(){
    }

	@Override
	public Object pk() {
		return this.id;
	}
}